<template>
  <div style="min-width: 1024px; overflow: auto">
    <div style="margin: 5px 5px; display: flex">
      <el-card style="width: 25%; height: 120px">
        <div style="display: flex">
          <div style="width: 80px">
            <svg class="iconStyle">
              <use xlink:href="#icon-shenqing"></use>
            </svg>
            我的申请
          </div>
          <div class="approvalItem">
            <span>我的申请:10</span>
            <span>等待审批:10</span>
            <span>审批完成:10</span>
          </div>
        </div>
      </el-card>
      <el-card style="width: 25%; margin-left: 5px; height: 120px">
        <div style="display: flex">
          <div style="width: 80px">
            <svg class="iconStyle">
              <use xlink:href="#icon-shenpi"></use>
            </svg>
            我的审批
          </div>
          <div class="approvalItem">
            <span>同意:10</span>
            <span>驳回:10</span>
            <span>不同意:10</span>
          </div>
          <!-- <div id="echarts-tow" style="width: 100%; height: 100%"></div> -->
        </div>
      </el-card>
      <el-card style="width: 25%; margin-left: 5px; height: 120px">
        <div style="display: flex">
          <div style="width: 80px">
            <svg class="iconStyle">
              <use xlink:href="#icon-daishenpi"></use>
            </svg>
            等待审批
          </div>
          <div class="approvalItem">
            <span>待审批:10</span>
          </div>
        </div>
      </el-card>
      <el-card style="width: 25%; margin-left: 5px; height: 120px">
        <div style="display: flex">
          <div style="width: 80px">
            <svg class="iconStyle">
              <use xlink:href="#icon-naozhong"></use>
            </svg>
            超时流程
          </div>
          <div class="approvalItem">
            <span>超时流程:10</span>
          </div>
        </div>
      </el-card>
      <el-card style="width: 25%; margin-left: 5px; height: 120px">
        <div style="display: flex">
          <div style="width: 80px">
            <svg class="iconStyle">
              <use xlink:href="#icon-naozhong"></use>
            </svg>
            抄送流程
          </div>
          <div class="approvalItem">
            <span>我的接收:10</span>
            <span>我的抄送:10</span>
          </div>
        </div>
      </el-card>
    </div>
    <div style="column-count: 4; column-gap: 0px">
      <div
        v-for="value in departmentFlowList"
        :key="value.key"
        class="depApproval"
        :style="{ boxShadow: `${randomColor()} 0px 0px 5px` }"
      >
        <div :style="{ backgroundColor: randomColor(), height: '3px' }"></div>
        <div class="depTitle">{{ value.label }}({{ value.children.length }})</div>
        <div
          v-if="value.children.length > 0"
          v-for="item in value.children"
          :key="item.key"
          class="depFormTitle"
        >
          <el-tooltip content="点击申请流程" effect="customized" placement="right">
            <span style="cursor: pointer" @click="addFlowApplyClick(item.key)">{{
              item.label
            }}</span>
          </el-tooltip>
        </div>
        <div v-else class="depFormTitle-no">无流程</div>
      </div>
    </div>
  </div>
  <addFlowApproval
    :is-visibles="addFlowModel.isVisibles"
    :dialogTitle="addFlowModel.dialogTitle"
    :flowId="addFlowModel.flowId"
    @closeBnt="colosClick"
  >
  </addFlowApproval>
</template>
<script lang="ts">
import { GetDepartmentFlow } from "@/api/flow";
import { treeOutPut } from "@/model/public/treeModel";
import { ElMessage } from "element-plus";
import { defineComponent, onMounted, reactive, ref } from "vue";
import chroma from "chroma-js";
import addFlowApproval from "@/views/flowApproval/myFlow/addFlowApproval.vue";
export default defineComponent({
  setup() {
    onMounted(() => {
      getDepartmentFlowMsg();
    });

    //新增流程模型
    const addFlowModel = reactive({
      isVisibles: false,
      dialogTitle: "",
      flowId: "",
    });

    //部门流程数据
    const departmentFlowList = ref<treeOutPut[]>([]);
    const getDepartmentFlowMsg = function () {
      departmentFlowList.value = [];
      GetDepartmentFlow().then(({ data, code, msg }) => {
        if (code == 200) {
          departmentFlowList.value = data[0].children;
        } else {
          ElMessage.warning(msg);
        }
      });
    };

    //新增
    const addFlowApplyClick = function (key: string) {
      addFlowModel.isVisibles = true;
      addFlowModel.dialogTitle = "新增流程";
      addFlowModel.flowId = key;
    };

    //关闭弹出层
    const colosClick = function () {
      addFlowModel.isVisibles = false;
    };

    //获取颜色
    function randomColor() {
      return chroma.random().hex();
    }
    return {
      departmentFlowList,
      randomColor,
      addFlowModel,
      colosClick,
      addFlowApplyClick,
    };
  },
  components: { addFlowApproval },
});
</script>
<style scoped>
.iconStyle {
  width: 60px;
  height: 60px;
}
.approvalItem {
  margin-left: 10px;
  display: grid;
  margin-top: -10px;
}
.approvalItem > * {
  margin-top: 5px;
  font-size: 14px;
}
.approvalItem > span {
  display: flex;
  align-items: center;
}

.flowCard {
  width: 25%;
  height: 120px;
}
.flowCard:not(:first-child) {
  margin-left: 5px;
}
.depApproval {
  margin: 5px 5px;
  min-width: 24%;
  background: #f5f5f5;
  height: max-content;
  break-inside: avoid;
}
/* .depApproval:hover {
  background: rgb(221, 226, 235);
} */
.depTitle {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 10px;
  height: 50px;
  font-size: 25px;
}
.depFormTitle {
  margin-top: 10px;
  text-align: left;
  margin-left: 10px;
  padding-bottom: 10px;
  display: flex;
  align-items: center;
}

.depFormTitle-no {
  margin-top: 10px;
  text-align: left;
  margin-left: 10px;
  padding-bottom: 5px;
}

.depFormTitle:hover {
  /* font-size: 18px; */
  font-weight: bold;
  color: white;
  background-color: rgba(19, 4, 240, 0.1);
  box-shadow: 0 3px 6px rgba(122, 63, 177, 0.1), 0 3px 6px rgba(122, 63, 177, 0.1);
  border-radius: 4px;
}
</style>
